(function(vc){
   vc.extends({
     
    data: {
       invoiceSellerModal: {
          edit: false,
          oiId: '',
          sellerName: '',
          sellerTaxNo: '',
          sellerPhone: '',
          sellerAddress: '',
          sellerBranchBank: '',
          sellerBankAccount: '',
          remark: ''
       }

    },
    _initMethod: function () {
       
    },
    _initEvent: function () {
        vc.on('invoiceSellerInfo', 'sellerInfoModal', function(item){
            if(item && item.oiId){
                $that.invoiceSellerModal.edit = true;
                $that.invoiceSellerModal.oiId = item.oiId;
                $that.invoiceSellerModal.sellerName = item.sellerName;
                $that.invoiceSellerModal.sellerTaxNo = item.sellerTaxNo;
                $that.invoiceSellerModal.sellerPhone = item.sellerPhone;
                $that.invoiceSellerModal.sellerAddress = item.sellerAddress;
                $that.invoiceSellerModal.sellerBranchBank = item.sellerBranchBank;
                $that.invoiceSellerModal.sellerBankAccount = item.sellerBankAccount;
                $that.invoiceSellerModal.remark = item.remark;
            }else{
                $that.invoiceSellerModal.edit = false;
                $that.invoiceSellerModal.sellerName =  vc.getData('/nav/getUserInfo').name;
            }
            $('#invoiceSellerInfoModel').modal('show');
        });
        
    },
    methods: {
        saveSellerInfo: function(){
            var _data = {
                oiId: $that.invoiceSellerModal.oiId,
                sellerName: $that.invoiceSellerModal.sellerName,
                sellerTaxNo: $that.invoiceSellerModal.sellerTaxNo,
                sellerPhone: $that.invoiceSellerModal.sellerPhone,
                sellerAddress:  $that.invoiceSellerModal.sellerAddress,
                sellerBranchBank: $that.invoiceSellerModal.sellerBranchBank,
                sellerBankAccount: $that.invoiceSellerModal.sellerBankAccount,
                remark: $that.invoiceSellerModal.remark
            };
            if(!_data.sellerName || !_data.sellerPhone || !_data.sellerTaxNo || !_data.sellerAddress 
                || !_data.sellerBranchBank || !_data.sellerBankAccount){
                    vc.toast('必填项不能为空');
                    return;
                }
            vc.http.apiPost('/invoice.saveSellerInfo', 
                JSON.stringify(_data), 
                {emulateJSON: true}, 
                function(json,res){
                    var _json = JSON.parse(json);
                    if(_json.code==0){
                        $('#invoiceSellerInfoModel').modal('hide');
                        vc.toast(_data.oiId?'修改销方数据成功':'添加销方数据成功');
                        vc.emit('reloadSellerData', 'list', {});
                    }else{
                        vc.toast(_json.msg);
                    }
                },
                function (errInfo,error) {
                    console.log('请求失败处理');
                    vc.toast(errInfo);
                }
            )
        }
    }

   });

})(window.vc);